@use '../../_styles/mixin.scss' as *;
@use './var.scss';

.o-figure {
  display: inline-flex;
  align-items: center;
  vertical-align: top;
  overflow: hidden;
  transition: background-color var(--o-duration-m2);
  border-radius: var(--figure-radius);
  position: relative;

  &.is-loading {
    &.is-colorful {
      background-color: var(--figure-prest-color);
    }
    img {
      opacity: 0;
    }
  }
  img {
    max-width: 100%;
    vertical-align: top;
    opacity: 1;
    transition: opacity var(--o-duration-m2), transform var(--o-easing-standard) 600ms;
    will-change: transform;
    border-radius: var(--figure-radius);
  }
  &.is-error {
    background-color: var(--figure-error-bk);
  }
}

.o-figure-main {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  right: 0;
  transition: background-color var(--o-easing-standard-in) var(--o-duration-m1);
}

.o-figure-hoverable {
  cursor: pointer;

  @include hover {
    img {
      transform: scale(1.05);
    }
  }
  &:active {
    img {
      transform: scale(1.02);
    }
    .o-figure-main {
      background-color: rgba(var(--o-black), 0.1);
    }
  }
}
.o-figure-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  padding-top: var(--figure-padding-top);
}
.o-figure-bg {
  background-size: var(--figure-fit);
  background-position: var(--figure-position);
  background-repeat: no-repeat;

  &.o-figure-no-ratio {
    // background 模式下且未设置 ratio 时，组件高度由 o-figure-main 中的内容撑开
    // o-figure-wrap 中的 IconImageError 作为背景图
    .o-figure-wrap {
      position: absolute;
      inset: 0;
    }
    .o-figure-main {
      position: relative;
    }
  }
}
.o-figure-img-ratio {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  object-fit: var(--figure-fit);
  object-position: var(--figure-position);
}

.o-figure-img {
  width: 100%;
  height: 100%;
  object-fit: var(--figure-fit);
  object-position: var(--figure-position);
}

.o-figure-view {
  cursor: zoom-in;
}

.o-figure-view-layer {
  width: 100%;
  height: 100%;
  cursor: zoom-out;
}
.o-figure-preview-wrapper {
  position: relative;
}
.o-figure-view-figure {
  width: 100%;
  height: 100%;
  --figure-fit: contain;
}

.o-figure-previewable {
  cursor: pointer;
}
.o-figure-preview-img {
  position: relative;
  img {
    vertical-align: top;
    max-width: 100vw;
    max-height: 100vh;
  }
}

.o-figure-error-wrap {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--figure-error-size);
  color: var(--figure-error-color);
}

// video-poster
.o-figure-video-poster {
  position: relative;
}

.o-figure-mask {
  background-color: rgba(var(--o-black), 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  border-radius: inherit;
}
.o-figure-play-icon {
  display: flex;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
  width: var(--figure-play-icon-size);
  height: var(--figure-play-icon-size);
  font-size: calc(var(--figure-play-icon-size) / 64 * 24);
  border-radius: 50%;
  color: var(--o-color-white);
  background-color: rgba(var(--o-white), 0.2);
  border: 1px solid rgba(var(--o-white), 0.6);
  backdrop-filter: blur(1px);
  .o-icon-video-play {
    margin-right: -0.2em;
  }
}

// content
.o-figure-title {
  font-size: var(--o-font_size-h3);
  line-height: var(--o-line_height-h3);
}
.o-figure-content {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  padding: 16px 24px;
  color: var(--o-color-white);
  background: linear-gradient(180deg, rgba(var(--o-black), 0) 0%, rgba(var(--o-black), 0.6) 100%);

  font-size: var(--o-font_size-tip1);
  line-height: var(--o-line_height-tip1);
}
